package com.gao.controller;

import com.gao.entities.Payment;
import com.gao.entities.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: suGar
 * @Date: 2022/10/14 9:14
 */
@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    //单机版
//    public static final String PAYMENT_URL = "http://localhost:8001";
    //集群
    public static final String PAYMENT_URL = "http://PAYMENT-SERVICE/";

    @Autowired
    private RestTemplate restTemplate;

    @PostMapping
    public Result create(Payment payment) {
        return restTemplate.postForObject(PAYMENT_URL + "payment", payment, Result.class);
    }

    @GetMapping("{id}")
    public Result getPayment(@PathVariable Integer id) {
        return restTemplate.getForObject(PAYMENT_URL + "payment/" + id, Result.class);
    }

    @GetMapping
    public Result getAllPayment() {
        return restTemplate.getForObject(PAYMENT_URL + "payment", Result.class);
    }

}
